package com.mission.schedule.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.lcf.refreshlibrary.PullToRefreshBase;
import com.lcf.refreshlibrary.PullToRefreshListView;
import com.lcf.refreshlibrary.PullToRefreshScrollView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mission.schedule.CommonDialog.NoteOtherRightMenuDialog;
import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.NoteLYBean;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.cutimage.Log;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.utils.CalendarChange;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.ListViewForScrollView;
import com.mission.schedule.utils.MyLinearLayout;
import com.mission.schedule.utils.ProgressUtil;
import com.mission.schedule.utils.ScreenUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;


@SuppressLint({"SimpleDateFormat", "HandlerLeak"})
public class QDFXDetailActivity extends BaseActivity implements OnClickListener {


    private LinearLayout back;
    private RelativeLayout my_friend_ll_right;
    PullToRefreshListView listview;
    List<NoteTitleDetailBean.ListBean> locallistBeanList = new ArrayList<>();
    Context context;

    SharedPrefUtil sharedPrefUtil = null;

    String title = "", title1 = "";
    String titleId;
    String path;
    String time;
    String name;
    String rednum;
    String goodnum = "0";
    String num;
    String userid;
    String uid;
    int type = 1;//5 发现过来的

    boolean isGood = false;
    boolean isOnRefresh = false;

    ListAdapter listAdapter;
    ListAdapter2 listAdapter2;
    ListAdapter3 listAdapter3;
    int stylee = 0;
    int isRead = 0;

    @Override
    protected void setListener() {
        back.setOnClickListener(this);
        my_friend_ll_right.setOnClickListener(this);

        listview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {


            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                isOnRefresh = true;
                getdata();
            }

            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<ListView> refreshView) {
                listview.onRefreshComplete();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();

        try {
            if (listAdapter != null) {
                listAdapter.notifyDataSetChanged();
            }
            if (listAdapter2 != null) {
                listAdapter2.notifyDataSetChanged();
            }
            if (listAdapter3 != null) {
                setAdapter();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.dx_detail_activity);
        title = getIntent().getStringExtra("title");
        titleId = getIntent().getStringExtra("titleId");
        path = getIntent().getStringExtra("path");
        time = getIntent().getStringExtra("time");
        name = getIntent().getStringExtra("name");
        rednum = getIntent().getStringExtra("redNum");
        goodnum = getIntent().getStringExtra("goodNum");
        num = getIntent().getStringExtra("num");
        uid = getIntent().getStringExtra("uid");
        type = getIntent().getIntExtra("type", 1);
        stylee = getIntent().getIntExtra("stylee", 0);
        rednum = (Integer.valueOf(rednum) + 1) + "";
        isRead = getIntent().getIntExtra("isRead", 0);

        back = (LinearLayout) findViewById(R.id.top_ll_back);
        my_friend_ll_right = (RelativeLayout) findViewById(R.id.my_friend_ll_right);
        listview = (PullToRefreshListView) findViewById(R.id.listview);
        if (type == 5) {
            listview.setMode(PullToRefreshBase.Mode.DISABLED);
        }

    }


    @Override
    protected void init(Bundle savedInstanceState) {
        context = this;

        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);

        userid = sharedPrefUtil.getString(this, ShareFile.USERFILE, ShareFile.USERID, "");
        queryISGood();
        getdata();
    }

    private void intentLy(String content, int id) {
        if (type == 6) {
            if (sharedPrefUtil.getString(context, ShareFile.USERFILE,
                    ShareFile.ISNEWYOUKE, "0").equals("0")) {
                Toast.makeText(context, "请注册", Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(this, QDFXDetailLYActivity.class);
                intent.putExtra("content", content);
                intent.putExtra("title", title);
                intent.putExtra("id", id);
                intent.putExtra("uid", uid);
                intent.putExtra("titleid", titleId);
                intent.putExtra("style", stylee);
                intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                startActivity(intent);
            }
        } else {
            Intent intent = new Intent(this, QDFXDetailLYActivity.class);
            intent.putExtra("content", content);
            intent.putExtra("title", title);
            intent.putExtra("id", id);
            intent.putExtra("uid", uid);
            intent.putExtra("titleid", titleId);
            intent.putExtra("style", stylee);
            intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
            startActivity(intent);
        }
    }

    @Override
    protected void setAdapter() {

        if (type == 6) {
            locallistBeanList = App.getDBcApplication().getTitleNoteDetailData(userid, titleId, false);
            Collections.sort(locallistBeanList, new Comparator<NoteTitleDetailBean.ListBean>() {
                @Override
                public int compare(NoteTitleDetailBean.ListBean lhs,
                                   NoteTitleDetailBean.ListBean rhs) {
                    if (lhs.orderId > rhs.orderId) {
                        return 1;
                    } else {
                        return -1;
                    }
                }
            });
            listAdapter3 = new ListAdapter3(locallistBeanList);
            listview.setAdapter(listAdapter3);
            listAdapter3.notifyDataSetChanged();
        } else if (type == 2) {//日程过来的
            Collections.sort(delListBeanList, new Comparator<DownSendNoteCalnderBean.DelListBean>() {
                @Override
                public int compare(DownSendNoteCalnderBean.DelListBean lhs,
                                   DownSendNoteCalnderBean.DelListBean rhs) {
                    if (lhs.orderId > rhs.orderId) {
                        return 1;
                    } else {
                        return -1;
                    }
                }
            });
            listAdapter2 = new ListAdapter2(delListBeanList);
            listview.setAdapter(listAdapter2);
            listAdapter2.notifyDataSetChanged();
        } else {
            Collections.sort(listBeanList, new Comparator<QDBean.ListBean>() {
                @Override
                public int compare(QDBean.ListBean lhs,
                                   QDBean.ListBean rhs) {
                    if (lhs.orderId > rhs.orderId) {
                        return 1;
                    } else {
                        return -1;
                    }
                }
            });
            listAdapter = new ListAdapter(listBeanList);
            listview.setAdapter(listAdapter);
            listAdapter.notifyDataSetChanged();
        }

        if (type != 5) {
            isOnRefresh = false;
            listview.onRefreshComplete();
        }

    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    if (!title1.isEmpty() || title.isEmpty()) {
                        notifyDataSetChanged();
                    }
                    break;
            }
        }
    };

    private void sendh(int what) {
        Message message = new Message();
        message.what = what;
        handler.sendMessage(message);
    }

    ProgressUtil progressUtil = new ProgressUtil();

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

//            case R.id.checkAll:
//                Intent intent = new Intent(this, QDFXDetailLYActivity.class);
//                intent.putExtra("content", title.isEmpty() ? title1 : title);
//                intent.putExtra("id", 0);
//                intent.putExtra("uid", uid);
//                intent.putExtra("titleid", titleId);
//                intent.putExtra("title", title.isEmpty() ? title1 : title);
//                intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
//                startActivity(intent);
//                break;

            case R.id.top_ll_back:
                onBackPressed();
                break;
            case R.id.my_friend_ll_right:
                if (type != 1) {
                    NoteOtherRightMenuDialog noteOtherRightMenuDialog = new NoteOtherRightMenuDialog(context, R.style.dialog_translucent, getWindowManager(), type == 6 ? true : false);
                    noteOtherRightMenuDialog.show();
                    noteOtherRightMenuDialog.setCallBack(new NoteOtherRightMenuDialog.CallBack() {
                        @Override
                        public void daiban() {
                            try {
                                App.getDBcApplication().insertScheduleData(title.isEmpty() ? title1 : title, DateUtil.formatDate(new Date()),
                                        DateUtil.formatDateTimeHm(new Date()), 1,
                                        0, 0, 1, 0,
                                        0, 0, DateUtil.formatDateTime(new Date()), "", type == 5 ? 1 : 0,
                                        type == 5 ? num : titleId, DateUtil.formatDateTimeSs(new Date()), 0, "", DateUtil.formatDateTime(new Date()),
                                        1, 0, 0, "完成任务", "g_88", type == 5 ? "发现" : name, 0, 0, 0, "",
                                        "", 0, 0, Integer.valueOf(uid),0,"","0","0");
                                addNums(titleId);
                                QueryAlarmData.writeAlarm(context.getApplicationContext());
                                Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                                Bundle extras = new Bundle();
                                intentappwidget.putExtras(extras);
                                sendBroadcast(intentappwidget);
                                Intent intent1 = new Intent(Const.SHUAXINDATA);
                                intent1.putExtra("data", "success");
                                intent1.putExtra("index", 1);
                                intent1.putExtra("what", 2);
                                context.sendBroadcast(intent1);

                                Toast.makeText(context, "添加成功", Toast.LENGTH_SHORT).show();

                                StringRequest request1 = new StringRequest(Request.Method.POST, URLConstants.清单留言加入清单到日程时候调用, new Response.Listener<String>() {
                                    @Override
                                    public void onResponse(String s) {
                                    }


                                }, new Response.ErrorListener() {
                                    @Override
                                    public void onErrorResponse(VolleyError volleyError) {

                                    }
                                }) {
                                    @Override
                                    protected Map<String, String> getParams() throws AuthFailureError {
                                        Map<String, String> map = new HashMap<String, String>();
                                        map.put("titleId", titleId);
                                        map.put("uId", uid);
                                        map.put("cuId", userid);
                                        return map;
                                    }
                                };
                                request1.setTag("sendsc");
                                request1.setRetryPolicy(new DefaultRetryPolicy(5000, 1, 1.0f));
                                App.getHttpQueues().add(request1);

                            } catch (NumberFormatException e) {
                                e.printStackTrace();
                            }
                        }

                        @Override
                        public void richeng() {
                            initRiliDiaLog(title.isEmpty() ? title1 : title);
                        }

                        @Override
                        public void sendnote() {
                            if (sharedPrefUtil.getString(getApplication(),
                                    ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "0").equals("-1")) {
                                Intent zhuanfa = new Intent(context, NewFriendsActivity.class);
                                if (type == 2) {
                                    zhuanfa.putExtra("type1", 0);
                                }
                                zhuanfa.putExtra("type", 2);
                                zhuanfa.putExtra("titleid", titleId);
                                zhuanfa.putExtra("title_userid", uid);
                                zhuanfa.putExtra("title", title.isEmpty() ? title1 : title);
                                zhuanfa.putExtra("titleimg", path);
                                zhuanfa.putExtra("noteusername", name);
                                startActivity(zhuanfa);
                            } else {
                                Toast.makeText(context, "请注册!", Toast.LENGTH_SHORT).show();
                            }
                        }

                        @Override
                        public void longimage() {
                            Intent intent1;
                            Bundle bundle = new Bundle();
                            if (type == 6) {
                                intent1 = new Intent(context, QDLongImageSaveActivity.class);
                                bundle.putSerializable("list", (Serializable) locallistBeanList);
                            } else if (type == 2) {
                                intent1 = new Intent(context, QDLongImageSaveActivity2.class);
                                bundle.putSerializable("list", (Serializable) delListBeanList);
                            } else {
                                intent1 = new Intent(context, QDLongImageSaveActivity1.class);
                                bundle.putSerializable("list", (Serializable) listBeanList);
                            }
                            intent1.putExtra("name", name);
                            intent1.putExtra("stylee", stylee);
                            intent1.putExtra("title", title);
                            intent1.putExtras(bundle);
                            startActivity(intent1);
                        }

                        @Override
                        public void savemyqd() {
                            NoteTitleDetailBean.TDelListBean tDelListBean = new NoteTitleDetailBean.TDelListBean();
                            tDelListBean.titleId = titleId;
                            tDelListBean.uid = Integer.valueOf(userid);
                            tDelListBean.id = App.getDBcApplication().getTiMinId() - 1;
                            tDelListBean.styles = stylee;
                            tDelListBean.changeTime = DateUtil.formatDateTimeSs(new Date());
                            tDelListBean.createTime = DateUtil.formatDateTimeSs(new Date());
                            tDelListBean.localTimes = DateUtil.formatDateTimeSs(new Date());
                            tDelListBean.ltype = 0;
                            tDelListBean.orderId = 0;
                            tDelListBean.copys = "0";
                            tDelListBean.filed = "0";
                            tDelListBean.titles = title;
                            tDelListBean.imgPath = path;
                            tDelListBean.imgUrl = "";
                            tDelListBean.nums = num;
                            tDelListBean.shareUrl = "";
                            if (title.isEmpty()) {
                                tDelListBean.remark = "1";
                            } else {
                                tDelListBean.remark = "0";
                            }
                            tDelListBean.remark1 = "0";
                            tDelListBean.remark2 = "";
                            tDelListBean.remark3 = (type == 5 ? "2" : "1");
                            tDelListBean.pname = name;
                            tDelListBean.puid = Integer.valueOf(uid);
                            tDelListBean.states = 0;
                            tDelListBean.sends = 0;
                            tDelListBean.openState = 0;
                            tDelListBean.other1 = "0";//1未读

                            App.getDBcApplication().saveNoteTitleData(tDelListBean);
                            App.getDBcApplication().updateNoteTitleState(tDelListBean.titleId, userid, 1, false);
                            Intent pull = new Intent();
                            pull.setAction("pullRecevier");
                            getApplication().sendBroadcast(pull);
                            Toast.makeText(context, "收藏成功!", Toast.LENGTH_SHORT).show();
                        }
                    });
                } else {
                    alterNewDialog();
                }
                break;
//            case R.id.zan:
//                if (!isGood) {
//                    good();
//                }
//                if (sharedPrefUtil.getString(context, ShareFile.USERFILE,
//                        ShareFile.ISYOUKE, "1").equals("1")) {
//
//                }else {
//                    Toast.makeText(context,"请注册",Toast.LENGTH_SHORT).show();
//                }
//                break;
            default:
                break;
        }
    }

    private void addNums(String titleid) {
        if (delListBeanList.size() > 0) {
            App.getDBcApplication().saveCalenderNoteData(titleid, listAdapter2.nums());
        } else if (listBeanList.size() > 0) {
            App.getDBcApplication().saveCalenderNoteData(titleid, listAdapter.nums());
        } else if (locallistBeanList.size() > 0) {
            App.getDBcApplication().saveCalenderNoteData(titleid, listAdapter3.nums());
        }

    }


    /**
     * 最新清单右滑对话框
     */
    private void alterNewDialog() {
        final Dialog dialog = new Dialog(QDFXDetailActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(QDFXDetailActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_qdfx_detail_right, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();

        more_pop_menu.findViewById(R.id.share_f).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                showShare();
            }
        });
        more_pop_menu.findViewById(R.id.share_p).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                showShare();
            }
        });
        more_pop_menu.findViewById(R.id.share_c).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                Intent intent1 = new Intent(context, QDLongImageSaveActivity1.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("list", (Serializable) listBeanList);
                intent1.putExtra("name", name);
                intent1.putExtra("stylee", stylee);
                intent1.putExtra("title", title);
                intent1.putExtras(bundle);
                startActivity(intent1);
            }
        });
        more_pop_menu.findViewById(R.id.canel_tv).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }


    //分享其他
    private void showShare() {
        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        // 关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setTitle(title);
        oks.setText(listBeanList.get(0).contents);

        String url = "http://www.keytimeapp.com/qingdan/qdlist-user.html?uId=" + userid + "&titleId=" + listBeanList.get(0).titleId + "&title=" + title + "&name=" + sharedPrefUtil.getString(context, ShareFile.USERFILE,
                ShareFile.USERNAME, "") + "&number=" + listBeanList.get(0).num + "&from=singlemessage&isappinstalled=1&type=1";
        oks.setUrl(url);
        oks.setImageUrl(URLConstants.图片 + sharedPrefUtil.getString(context,
                ShareFile.USERFILE, ShareFile.USERPHOTOPATH, "") + "&imageType=2&imageSizeType=3");
        oks.setCallback(new newOneCallBack());
        // 启动分享GUI
        oks.show(this);
    }

    class newOneCallBack implements PlatformActionListener {

        @Override
        public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
        }

        @Override
        public void onError(Platform platform, int i, Throwable throwable) {
        }

        @Override
        public void onCancel(Platform platform, int i) {
        }
    }


    private void queryISGood() {
        HttpUtils httpUtils = new HttpUtils(10000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("num", num);
        params.addBodyParameter("uId", userid);
        httpUtils.send(HttpMethod.POST, URLConstants.清单发现详情是否已赞, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    QDFXGLListActivity.updateQDFXBean bean = gson.fromJson(responseInfo.result, QDFXGLListActivity.updateQDFXBean.class);
                    if (bean.status == 0) {
                        isGood = true;
                        notifyDataSetChanged();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
            }
        });
    }

    private void clickEndstate(final int position, final int type, final int id, final int endtype, final ImageView image, final int listType) {
        final ProgressUtil progressUtil = new ProgressUtil();
        progressUtil.ShowProgress(context, true, true, "正在修改");
        HttpUtils httpUtils = new HttpUtils(5000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("titleId", titleId);
        params.addBodyParameter("uId", uid);
        params.addBodyParameter("cuId", userid);
        params.addBodyParameter("type", type + "");
        params.addBodyParameter("id", id + "");
        params.addBodyParameter("row1", "▶︎ @" + sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "") + " 修改了清单状态");
        params.addBodyParameter("row2", "#" + (title.isEmpty() ? title1 : title) + "#");
        params.addBodyParameter("oldName", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, ""));
        httpUtils.send(HttpMethod.POST, URLConstants.清单留言收藏方状态表添加状态, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    AddTbUserDetailLyStatesBean bean = gson.fromJson(responseInfo.result, AddTbUserDetailLyStatesBean.class);
                    if (bean.status == 0) {
                        if (endtype == 0) {
                            if (type == 0) {
                                image.setBackground(getResources().getDrawable(R.mipmap.btn_qd_unfinish_c));
                                ly("取消结束了清单子项", id);
                            } else {
                                image.setBackground(getResources().getDrawable(R.mipmap.btn_qd_finish_c));
                                ly("结束了清单子项", id);
                            }
                        } else if (endtype == 1) {
                            if (type == 0) {
                                image.setBackground(getResources().getDrawable(R.mipmap.icon_santai1));
                                ly("将清单子项设为未结束", id);
                            } else if (type == 1) {
                                image.setBackground(getResources().getDrawable(R.mipmap.icon_santai2));
                                ly("将清单子项设为待结束状态", id);
                            } else {
                                image.setBackground(getResources().getDrawable(R.mipmap.icon_santai3));
                                ly("将清单子项设为已结束", id);
                            }
                        }
                        if (listType == 0) {
                            listAdapter.updateEndstate(position, type);
                        } else if (listType == 1) {
                            listAdapter2.updateEndstate(position, type);
                        } else if (listType == 2) {
                            listAdapter3.updateEndstate(position, type);
                        }
                    }
                } else {
                    Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                }
                progressUtil.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                progressUtil.dismiss();
                Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    /**
     * 修改清单状态bean
     */
    class AddTbUserDetailLyStatesBean {

        /**
         * status : 0
         * downTime : 2017-07-17T15:37:44
         * message : 成功
         * list : null
         * tDelList : null
         * delList : null
         */

        public int status;
        public String downTime;
        public String message;
        public Object list;
        public Object tDelList;
        public Object delList;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getList() {
            return list;
        }

        public void setList(Object list) {
            this.list = list;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }
    }

    private void good() {
        HttpUtils httpUtils = new HttpUtils(10000);
        RequestParams params = new RequestParams();
        String path;
        if (type != 1 && type != 5) {
            path = URLConstants.清单公告点赞;
            params.addBodyParameter("titleId", titleId);
            params.addBodyParameter("type", "0");
        } else {
            path = URLConstants.清单发现详情点赞;
            params.addBodyParameter("num", num);
            params.addBodyParameter("puId", uid);
        }

        params.addBodyParameter("uId", userid);

        httpUtils.send(HttpMethod.POST, path, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    QDFXGLListActivity.updateQDFXBean bean = gson.fromJson(responseInfo.result, QDFXGLListActivity.updateQDFXBean.class);
                    if (bean.status == 0) {
                        goodnum = (Integer.valueOf(goodnum) + 1) + "";
                        isGood = true;
                        isZan = true;
                        if (type != 1 && type != 5) {
                            String rizhi = sharedPrefUtil.getString(context,
                                    ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
                            sharedPrefUtil.putString(context,
                                    ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, rizhi + "," + titleId);
                        }
                        notifyDataSetChanged();
                    }

                    if (bean.status == 4) {
                        Toast.makeText(QDFXDetailActivity.this, "已点过赞", Toast.LENGTH_SHORT).show();
                        isGood = true;
                        notifyDataSetChanged();
                    }
                } else {
                    Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });
    }

    List<QDBean.ListBean> listBeanList = new ArrayList<>();
    List<DownSendNoteCalnderBean.DelListBean> delListBeanList = new ArrayList<>();
    List<DownSendNoteCalnderBean.ListBean> listBeanList1 = new ArrayList<>();

    private void getdata() {
//        NoteTitleDetailBean.TDelListBean bean = App.getDBcApplication().getOneNoteTitlesData(userid, titleId);
//        if (bean.titleId != null) {
//            title = bean.titles;
//            titleId = bean.titleId;
//            uid = bean.uid + "";
//            stylee = bean.styles;
//            path = bean.imgPath;
//            time = bean.createTime.replace('T', ' ');
//
//            username.setText("@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
//            if (path.isEmpty()) {
//                header_image.setVisibility(View.GONE);
//            } else {
//                header_image.setVisibility(View.VISIBLE);
//                String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
//                ImageLoader.getInstance().displayImage(imageUrl, header_image, base_options);
//            }
//            int num = App.getDBcApplication().getTitleNoteDetailData(userid, titleId, false).size();
//            String title_new;
//            if (stylee == 0) {
//                int tick = App.getDBcApplication().getNoteDetailEndstateNums(titleId, userid);
//                if (num == 0) {
//                    title_new = "0";
//                } else {
//                    title_new = tick + "/" + num;
//                }
//            } else if (stylee == 4) {
//                int tick1 = App.getDBcApplication().getNoteDetailEndstateNums(titleId, userid, 1);
//                int tick2 = App.getDBcApplication().getNoteDetailEndstateNums(titleId, userid, 2);
//                if (num == 0) {
//                    title_new = "0";
//                } else {
//                    title_new = tick1 + "/" + tick2 + "/" + num;
//                }
//            } else {
//                title_new = num + "";
//            }
//            App.getDBcApplication().saveCalenderNoteData(titleId, title_new);
//            setAdapter();
//        } else {
        final ProgressUtil progressUtil = new ProgressUtil();
        progressUtil.ShowProgress(this, true, true, "下载中...");
        HttpUtils httpUtils = new HttpUtils(10000);
        RequestParams params = new RequestParams();
        final String pathurl;
        if (type == 0) {
            params.addBodyParameter("titleId", titleId);
            pathurl = URLConstants.清单常见问题详情下载;
        } else if (type == 2) {
            params.addBodyParameter("titleId", titleId);
            params.addBodyParameter("cuId", userid);
            pathurl = URLConstants.清单留言查询单个公开清单;
        } else {
            params.addBodyParameter("num", num);
            pathurl = URLConstants.清单发现分组自己清单详情查询;
        }
        params.addBodyParameter("uId", uid);
        httpUtils.send(HttpMethod.POST, pathurl, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    if (type == 2) {
                        DownSendNoteCalnderBean downSendNoteCalnderBean = gson.fromJson(responseInfo.result, DownSendNoteCalnderBean.class);
                        if (downSendNoteCalnderBean.status == 0) {
                            if (downSendNoteCalnderBean.list != null) {
                                listBeanList1 = downSendNoteCalnderBean.list;
                            }
                            if (downSendNoteCalnderBean.delList != null) {
                                delListBeanList = downSendNoteCalnderBean.delList;
                            }
                            if (listBeanList1 != null) {

                                for (DownSendNoteCalnderBean.ListBean listBean : listBeanList1) {
                                    title = listBean.titles;
                                    titleId = listBean.titleId;
                                    uid = listBean.uid + "";
                                    stylee = listBean.styles;
                                    path = listBean.imgPath;
                                    time = listBean.createTime.replace('T', ' ');
                                    notifyDataSetChanged();
                                }

                            }
                            if (delListBeanList != null) {
                                int tick1 = 0;
                                int tick2 = 0;
                                for (DownSendNoteCalnderBean.DelListBean delListBean : delListBeanList) {
                                    if (delListBean.endstate == 1) {
                                        tick1 += 1;
                                    }
                                    if (delListBean.endstate == 2) {
                                        tick2 += 1;
                                    }
                                }
                                String title_new;
                                if (stylee == 0) {
                                    if (delListBeanList.size() == 0) {
                                        title_new = "0";
                                    } else {
                                        title_new = tick1 + "/" + delListBeanList.size();
                                    }
                                } else if (stylee == 4) {
                                    if (delListBeanList.size() == 0) {
                                        title_new = "0";
                                    } else {
                                        title_new = tick1 + "/" + tick2 + "/" + delListBeanList.size();
                                    }
                                } else {
                                    title_new = delListBeanList.size() + "";
                                }
                                App.getDBcApplication().saveCalenderNoteData(titleId, title_new);
                            }
                            setAdapter();
                        }
                    } else {
                        QDBean bean = gson.fromJson(responseInfo.result, QDBean.class);
                        if (bean.status == 0) {
                            listBeanList.clear();
                            listBeanList = bean.list;

                            setAdapter();
                        }
                    }

                } else {
                    Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
                }
                progressUtil.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                progressUtil.dismiss();
                Toast.makeText(QDFXDetailActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
            }
        });

        if (isRead == 1) {
            ly();
            isRead = 0;
        }

        if (type != 5) {
            HttpUtils httpUtils0 = new HttpUtils(5000);
            RequestParams params0 = new RequestParams();
            params0.addBodyParameter("titleId", titleId);
            params0.addBodyParameter("type", "5");
            params0.addBodyParameter("uId", uid);
            params0.addBodyParameter("nowPage", "1");
            params0.addBodyParameter("pageNum", "2000");
            params0.addBodyParameter("id", "");
            params0.addBodyParameter("changeTime", App.getDBcApplication().getOneNoteLYDataDownTime(titleId).isEmpty() ? "" :
                    App.getDBcApplication().getOneNoteLYDataDownTime(titleId).replace("T", " "));
            httpUtils0.send(HttpMethod.POST, URLConstants.清单留言查询留言主表, params0, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    if (!TextUtils.isEmpty(responseInfo.result)) {
                        Gson gson = new Gson();
                        NoteLYBean noteLYBean = gson.fromJson(responseInfo.result, NoteLYBean.class);
                        if (noteLYBean.status == 0) {
                            List<NoteLYBean.PageBean.ItemsBean> list = noteLYBean.page.items;
                            if (list != null) {
                                for (NoteLYBean.PageBean.ItemsBean bean : list) {
                                    String changeTime = App.getDBcApplication().getOneNoteLYData(titleId, bean.cId).changeTime;
                                    App.getDBcApplication().insertNoteLYData(bean, noteLYBean.downTime.replace("T", " "));
                                    Date downDate = DateUtil.parseDateTime(bean.changeTime.replace("T", " "));
                                    if (changeTime == null) {
                                        changeTime = DateUtil.formatDateTimeSs(new Date());
                                    }
                                    Date loadDate = DateUtil.parseDateTime(changeTime.replace("T", " "));
                                    if (downDate.compareTo(loadDate) == 1) {
                                        App.getDBcApplication().updateNoteLYDataIsNew(titleId, bean.id, 1);
                                    }

                                }
                                notifyDataSetChanged();
                            }
                        }
                    }
                    listview.onRefreshComplete();
                }

                @Override
                public void onFailure(HttpException e, String s) {
                    listview.onRefreshComplete();
                }
            });
        }

        if (type != 1 && type != 5) {
            HttpUtils httpUtils0 = new HttpUtils(10000);
            RequestParams params0 = new RequestParams();
            params0.addBodyParameter("titleId", titleId);
            params0.addBodyParameter("type", "1");
            params0.addBodyParameter("uId", uid);
            httpUtils0.send(HttpMethod.POST, URLConstants.清单公告点赞, params0, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {

                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });

            HttpUtils httpUtils1 = new HttpUtils(10000);
            RequestParams params1 = new RequestParams();
            params1.addBodyParameter("titleId", titleId);
            params1.addBodyParameter("uId", uid);
            httpUtils1.send(HttpMethod.POST, URLConstants.清单公告下载数量, params1, new RequestCallBack<String>() {
                @Override
                public void onSuccess(ResponseInfo<String> responseInfo) {
                    if (!TextUtils.isEmpty(responseInfo.result)) {
                        Gson gson = new Gson();
                        GONGGAODOWNBEAN bean = gson.fromJson(responseInfo.result, GONGGAODOWNBEAN.class);
                        if (bean.status == 0) {
                            lis.clear();
                            lis = bean.list;
                            if (lis.size() > 0) {
                                goodnum = lis.get(0).goodNum + "";
                                rednum = lis.get(0).redNum + "";
                                notifyDataSetChanged();
                            }
                        }

                    }
                }

                @Override
                public void onFailure(HttpException e, String s) {

                }
            });

        }
    }

    private void notifyDataSetChanged() {
        if (type == 6) {
            listAdapter3.notifyDataSetChanged();
        } else if (type == 2) {
            listAdapter2.notifyDataSetChanged();
        } else {
            listAdapter.notifyDataSetChanged();
        }
    }

    List<GONGGAODOWNBEAN.ListBean> lis = new ArrayList<>();

    class GONGGAODOWNBEAN {


        /**
         * status : 0
         * downTime : 2017-06-16T10:55:55
         * message : 成功
         * list : [{"redNum":1,"noNum":0,"remark2":"","id":35,"remark1":"","goodNum":1,"titleId":"20170608144416483157","uid":5001,"changeTime":"2017-06-16T10:55:31"}]
         * tDelList : null
         * delList : null
         */

        public int status;
        public String downTime;
        public String message;
        public Object tDelList;
        public Object delList;
        public List<ListBean> list;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean {
            /**
             * redNum : 1
             * noNum : 0
             * remark2 :
             * id : 35
             * remark1 :
             * goodNum : 1
             * titleId : 20170608144416483157
             * uid : 5001
             * changeTime : 2017-06-16T10:55:31
             */

            public int redNum;
            public int noNum;
            public String remark2;
            public int id;
            public String remark1;
            public int goodNum;
            public String titleId;
            public int uid;
            public String changeTime;

            public int getRedNum() {
                return redNum;
            }

            public void setRedNum(int redNum) {
                this.redNum = redNum;
            }

            public int getNoNum() {
                return noNum;
            }

            public void setNoNum(int noNum) {
                this.noNum = noNum;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public int getGoodNum() {
                return goodNum;
            }

            public void setGoodNum(int goodNum) {
                this.goodNum = goodNum;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }

            public String getChangeTime() {
                return changeTime;
            }

            public void setChangeTime(String changeTime) {
                this.changeTime = changeTime;
            }
        }
    }

    boolean isZan = false;


    @Override
    public void onBackPressed() {
        isHongdian();
        Intent intent = new Intent();
        intent.putExtra("goodnum", isZan ? 1 : 0);
        setResult(0, intent);
        super.onBackPressed();
        this.finish();
    }

    private void isHongdian() {
        int isread = App.getDBcApplication().getOneNoteLYDataIsRead(titleId);
        if (isread > 0) {
            App.getDBcApplication().updateNoteTitleOther1(titleId, userid, 1);
        } else {
            App.getDBcApplication().updateNoteTitleOther1(titleId, userid, 0);
        }
    }

    private void intentLy(int position) {
        if (type != 5) {
            if (type == 6) {
                if (locallistBeanList.size() > 0) {
                    intentLy(locallistBeanList.get(position).contents, locallistBeanList.get(position).id);
                }
            } else {
                if (delListBeanList.size() > 0) {
                    intentLy(delListBeanList.get(position).contents, delListBeanList.get(position).id);
                } else if (listBeanList.size() > 0) {
                    intentLy(listBeanList.get(position).contents, listBeanList.get(position).id);
                }
            }
        }
    }

    boolean istitle1 = false;
    String where = "";

    class ListAdapter extends BaseAdapter {

        List<QDBean.ListBean> list;

        public ListAdapter(List<QDBean.ListBean> list) {
            this.list = list;
        }

        public void updateEndstate(int position, int endstate) {
            list.get(position).endstate = endstate;
        }

        public String nums() {
            int tick1 = 0;
            int tick2 = 0;
            for (QDBean.ListBean listBean : list) {
                if (listBean.endstate == 1) {
                    tick1 += 1;
                }
                if (listBean.endstate == 2) {
                    tick2 += 1;
                }
            }
            String title_new;
            if (stylee == 0) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + list.size();
                }
            } else if (stylee == 4) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + tick2 + "/" + list.size();
                }
            } else {
                title_new = list.size() + "";
            }

            return title_new;
        }

        @Override
        public int getCount() {
            return list.size() + 2;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0) {
                return 0;
            } else if (position == list.size() + 1) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public int getViewTypeCount() {
            return 3;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            OneHolder oneHolder = null;
            TwoHolder twoHolder = null;
            int viewtype = getItemViewType(position);
            if (convertView == null) {
                switch (viewtype) {
                    case 0:
                        oneHolder = new OneHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_header_view, parent, false);
                        oneHolder.title = (TextView) convertView.findViewById(R.id.title);
                        oneHolder.username = (TextView) convertView.findViewById(R.id.username);
                        oneHolder.header_image = (ImageView) convertView.findViewById(R.id.header_image);
                        convertView.setTag(oneHolder);
                        break;
                    case 1:
                        twoHolder = new TwoHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_foolter_view, parent, false);
                        twoHolder.checkAlltext = (TextView) convertView.findViewById(R.id.checkAlltext);
                        twoHolder.lttext = (TextView) convertView.findViewById(R.id.lttext);
                        twoHolder.number = (TextView) convertView.findViewById(R.id.number);
                        twoHolder.zan = (TextView) convertView.findViewById(R.id.zan);
                        twoHolder.zan_num = (TextView) convertView.findViewById(R.id.zan_num);
                        twoHolder.newly_ll = (LinearLayout) convertView.findViewById(R.id.newly_ll);
                        twoHolder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        convertView.setTag(twoHolder);
                        break;
                    case 2:
                        holder = new ViewHolder();

                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.qdfx_de_list_item, parent, false);
                        holder.content_tv = (TextView) convertView.findViewById(R.id.content_tv);
                        holder.xh = (TextView) convertView.findViewById(R.id.xh);
                        holder.dd = (ImageView) convertView.findViewById(R.id.dd);
                        holder.ch = (ImageView) convertView.findViewById(R.id.ch);
                        holder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        holder.ll = (RelativeLayout) convertView.findViewById(R.id.ll);
                        holder.santai = (ImageView) convertView.findViewById(R.id.santai);
                        holder.emty_v = convertView.findViewById(R.id.emty_v);
                        holder.line = convertView.findViewById(R.id.line);
                        holder.cl = (LinearLayout) convertView.findViewById(R.id.cl);
                        holder.ly_tv = (TextView) convertView.findViewById(R.id.ly_tv);

                        convertView.setTag(holder);
                        break;
                }
            } else {
                switch (viewtype) {
                    case 0:
                        oneHolder = (OneHolder) convertView.getTag();
                        break;
                    case 1:
                        twoHolder = (TwoHolder) convertView.getTag();
                        break;
                    case 2:
                        holder = (ViewHolder) convertView.getTag();
                        break;
                }
            }
            switch (viewtype) {
                case 0:
                    if (title.isEmpty()) {
                        oneHolder.title.setVisibility(View.GONE);
                    } else {
                        oneHolder.title.setText(title);
                    }

                    oneHolder.username.setText("@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));

                    if (path.isEmpty()) {
                        oneHolder.header_image.setVisibility(View.GONE);
                    } else {
                        oneHolder.header_image.setVisibility(View.VISIBLE);
                        String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
                        ImageLoader.getInstance().displayImage(imageUrl, oneHolder.header_image, base_options);
                    }

                    oneHolder.username.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                Intent intent = new Intent(context, NoteOtherListActivity.class);
                                intent.putExtra("name", name);
                                intent.putExtra("puid", uid);
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 1:
                    if (type == 5) {
                        twoHolder.newly_ll.setVisibility(View.GONE);
                    } else {
                        twoHolder.newly_ll.setVisibility(View.VISIBLE);
                    }
                    twoHolder.number.setText("浏览" + StringUtils.getIsStringEqulesNull(rednum) + "次");
                    twoHolder.zan_num.setText(StringUtils.getIsStringEqulesNull(goodnum) + "人");
                    twoHolder.zan.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (!isGood) {
                                good();
                            }
                        }
                    });
                    if (type != 1 && type != 5) {
                        String rizhi = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
                        String[] ri = rizhi.split(",");
                        if (ri.length > 0) {
                            for (String item : ri) {
                                if (item.equals(titleId)) {
                                    twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                                    twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                                    isGood = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (isGood) {
                        twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                        twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                    }
                    if (type != 5) {
                        where = "";
                        if (delListBeanList.size() > 0) {
                            for (DownSendNoteCalnderBean.DelListBean bean : delListBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (listBeanList.size() > 0) {
                            for (QDBean.ListBean bean : listBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (locallistBeanList.size() > 0) {
                            for (NoteTitleDetailBean.ListBean bean : locallistBeanList) {
                                where += bean.id + ",";
                            }
                        }
                        if (where.isEmpty()) {
                            where = " cId = 0 ";
                        } else {
                            where = " cId not in (" + where.substring(0, where.length() - 1) + ") ";
                        }
                        NoteLYBean.PageBean.ItemsBean bean = App.getDBcApplication().getOneNoteLYData(titleId, where);
                        if (bean != null) {
                            twoHolder.lttext.setText("@" + bean.lyName + ": " + bean.mess);

                            if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, bean.id) == 1) {
                                twoHolder.guoqi_img.setVisibility(View.VISIBLE);
                            } else {
                                twoHolder.guoqi_img.setVisibility(View.GONE);
                            }
                        }


                    }
                    twoHolder.newly_ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type == 6) {
                                if (sharedPrefUtil.getString(context, ShareFile.USERFILE,
                                        ShareFile.ISNEWYOUKE, "0").equals("0")) {
                                    Toast.makeText(context, "请注册", Toast.LENGTH_SHORT).show();
                                } else {
                                    Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                    intent.putExtra("where", where);
                                    intent.putExtra("wheretype", 1);
                                    intent.putExtra("content", title.isEmpty() ? title1 : title);
                                    intent.putExtra("id", 0);
                                    intent.putExtra("uid", uid);
                                    intent.putExtra("style", stylee);
                                    intent.putExtra("titleid", titleId);
                                    intent.putExtra("title", title);
                                    intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                    startActivity(intent);
                                }
                            } else {
                                Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                intent.putExtra("where", where);
                                intent.putExtra("wheretype", 1);
                                intent.putExtra("content", title.isEmpty() ? title1 : title);
                                intent.putExtra("id", 0);
                                intent.putExtra("uid", uid);
                                intent.putExtra("style", stylee);
                                intent.putExtra("titleid", titleId);
                                intent.putExtra("title", title);
                                intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 2:
                    final ViewHolder finalHolder = holder;
                    holder.ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                if (finalHolder.ch.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate == 0 ? 1 : 0;
                                    clickEndstate(position - 1, endstate, list.get(position - 1).id, 0, finalHolder.ch, 0);
                                } else if (finalHolder.santai.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate;
                                    if (endstate == 0) {
                                        clickEndstate(position - 1, 1, list.get(position - 1).id, 1, finalHolder.santai, 0);
                                    } else if (endstate == 1) {
                                        clickEndstate(position - 1, 2, list.get(position - 1).id, 1, finalHolder.santai, 0);
                                    } else if (endstate == 2) {
                                        clickEndstate(position - 1, 0, list.get(position - 1).id, 1, finalHolder.santai, 0);
                                    }
                                }
                            }

                        }
                    });

                    holder.cl.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                intentLy(position - 1);
                            }
                        }
                    });

                    if (list.size() > 0) {

                        NoteLYBean.PageBean.ItemsBean itemsBean = App.getDBcApplication().getOneNoteLYData(titleId, list.get(position - 1).id);
                        if (itemsBean != null) {
                            if (itemsBean.mess != null && itemsBean.lyName != null && itemsBean.cId == list.get(position - 1).id) {
                                holder.ly_tv.setVisibility(View.VISIBLE);
                                holder.ly_tv.setText("@" + itemsBean.lyName + ": " + itemsBean.mess);
                            } else {
                                holder.ly_tv.setVisibility(View.GONE);
                            }
                            if (type != 5) {
                                if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, list.get(position - 1).id) == 1) {
                                    holder.guoqi_img.setVisibility(View.VISIBLE);
                                } else {
                                    holder.guoqi_img.setVisibility(View.GONE);
                                }
                            }
                        }

                        if (!istitle1) {
                            if (!list.get(position - 1).contents.isEmpty()) {
                                title1 = list.get(position - 1).contents;
                                sendh(0);
                                istitle1 = true;
                            }
                        }

                        if (stylee == 0) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_unfinish_c));
                                } else {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_finish_c));
                                }
                            }
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 1) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.VISIBLE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 2) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 3) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                            holder.emty_v.setVisibility(View.VISIBLE);
                        } else if (stylee == 4) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai1));
                                } else if (list.get(position - 1).endstate == 1) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai2));
                                } else {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai3));
                                }
                            }
                        }

                        setcolor(list.get(position - 1).contents, holder.content_tv);
                        holder.xh.setText((position) + ".");
                    }

                    break;
            }
            return convertView;
        }


        class ViewHolder {
            TextView xh, content_tv, ly_tv;
            ImageView ch, dd, santai, guoqi_img;
            View emty_v, line;
            RelativeLayout ll;
            LinearLayout cl;
        }

        class OneHolder {
            TextView title, username, number;
            ImageView header_image;
        }

        class TwoHolder {
            TextView checkAlltext, lttext, number, zan, zan_num;
            LinearLayout newly_ll;
            ImageView guoqi_img;
        }


    }

    class ListAdapter2 extends BaseAdapter {

        List<DownSendNoteCalnderBean.DelListBean> list;

        public ListAdapter2(List<DownSendNoteCalnderBean.DelListBean> list) {
            this.list = list;
        }

        public void updateEndstate(int position, int endstate) {
            list.get(position).endstate = endstate;
        }

        public String nums() {
            int tick1 = 0;
            int tick2 = 0;
            for (DownSendNoteCalnderBean.DelListBean listBean : list) {
                if (listBean.endstate == 1) {
                    tick1 += 1;
                }
                if (listBean.endstate == 2) {
                    tick2 += 1;
                }
            }
            String title_new;
            if (stylee == 0) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + list.size();
                }
            } else if (stylee == 4) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + tick2 + "/" + list.size();
                }
            } else {
                title_new = list.size() + "";
            }

            return title_new;
        }

        @Override
        public int getCount() {
            return list.size() + 2;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0) {
                return 0;
            } else if (position == list.size() + 1) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public int getViewTypeCount() {
            return 3;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            OneHolder oneHolder = null;
            TwoHolder twoHolder = null;
            int viewtype = getItemViewType(position);
            if (convertView == null) {
                switch (viewtype) {
                    case 0:
                        oneHolder = new OneHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_header_view, parent, false);
                        oneHolder.title = (TextView) convertView.findViewById(R.id.title);
                        oneHolder.username = (TextView) convertView.findViewById(R.id.username);
                        oneHolder.header_image = (ImageView) convertView.findViewById(R.id.header_image);
                        convertView.setTag(oneHolder);
                        break;
                    case 1:
                        twoHolder = new TwoHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_foolter_view, parent, false);
                        twoHolder.checkAlltext = (TextView) convertView.findViewById(R.id.checkAlltext);
                        twoHolder.lttext = (TextView) convertView.findViewById(R.id.lttext);
                        twoHolder.number = (TextView) convertView.findViewById(R.id.number);
                        twoHolder.zan = (TextView) convertView.findViewById(R.id.zan);
                        twoHolder.zan_num = (TextView) convertView.findViewById(R.id.zan_num);
                        twoHolder.newly_ll = (LinearLayout) convertView.findViewById(R.id.newly_ll);
                        twoHolder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        convertView.setTag(twoHolder);
                        break;
                    case 2:
                        holder = new ViewHolder();

                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.qdfx_de_list_item, parent, false);
                        holder.content_tv = (TextView) convertView.findViewById(R.id.content_tv);
                        holder.xh = (TextView) convertView.findViewById(R.id.xh);
                        holder.dd = (ImageView) convertView.findViewById(R.id.dd);
                        holder.ch = (ImageView) convertView.findViewById(R.id.ch);
                        holder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        holder.ll = (RelativeLayout) convertView.findViewById(R.id.ll);
                        holder.santai = (ImageView) convertView.findViewById(R.id.santai);
                        holder.emty_v = convertView.findViewById(R.id.emty_v);
                        holder.line = convertView.findViewById(R.id.line);
                        holder.cl = (LinearLayout) convertView.findViewById(R.id.cl);
                        holder.ly_tv = (TextView) convertView.findViewById(R.id.ly_tv);

                        convertView.setTag(holder);
                        break;
                }
            } else {
                switch (viewtype) {
                    case 0:
                        oneHolder = (OneHolder) convertView.getTag();
                        break;
                    case 1:
                        twoHolder = (TwoHolder) convertView.getTag();
                        break;
                    case 2:
                        holder = (ViewHolder) convertView.getTag();
                        break;
                }
            }
            switch (viewtype) {
                case 0:
                    if (title.isEmpty()) {
                        oneHolder.title.setVisibility(View.GONE);
                    } else {
                        oneHolder.title.setText(title);
                    }

                    oneHolder.username.setText("@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));

                    if (path.isEmpty()) {
                        oneHolder.header_image.setVisibility(View.GONE);
                    } else {
                        oneHolder.header_image.setVisibility(View.VISIBLE);
                        String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
                        ImageLoader.getInstance().displayImage(imageUrl, oneHolder.header_image, base_options);
                    }

                    oneHolder.username.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                Intent intent = new Intent(context, NoteOtherListActivity.class);
                                intent.putExtra("name", name);
                                intent.putExtra("puid", uid);
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 1:
                    if (type == 5) {
                        twoHolder.newly_ll.setVisibility(View.GONE);
                    } else {
                        twoHolder.newly_ll.setVisibility(View.VISIBLE);
                    }
                    twoHolder.number.setText("浏览" + StringUtils.getIsStringEqulesNull(rednum) + "次");
                    twoHolder.zan_num.setText(StringUtils.getIsStringEqulesNull(goodnum) + "人");
                    twoHolder.zan.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (!isGood) {
                                good();
                            }
                        }
                    });
                    if (type != 1 && type != 5) {
                        String rizhi = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
                        String[] ri = rizhi.split(",");
                        if (ri.length > 0) {
                            for (String item : ri) {
                                if (item.equals(titleId)) {
                                    twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                                    twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                                    isGood = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (isGood) {
                        twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                        twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                    }
                    if (type != 5) {
                        where = "";
                        if (delListBeanList.size() > 0) {
                            for (DownSendNoteCalnderBean.DelListBean bean : delListBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (listBeanList.size() > 0) {
                            for (QDBean.ListBean bean : listBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (locallistBeanList.size() > 0) {
                            for (NoteTitleDetailBean.ListBean bean : locallistBeanList) {
                                where += bean.id + ",";
                            }
                        }
                        if (where.isEmpty()) {
                            where = " cId = 0 ";
                        } else {
                            where = " cId not in (" + where.substring(0, where.length() - 1) + ") ";
                        }
                        NoteLYBean.PageBean.ItemsBean bean = App.getDBcApplication().getOneNoteLYData(titleId, where);
                        if (bean != null) {
                            twoHolder.lttext.setText("@" + bean.lyName + ": " + bean.mess);

                            if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, bean.id) == 1) {
                                twoHolder.guoqi_img.setVisibility(View.VISIBLE);
                            } else {
                                twoHolder.guoqi_img.setVisibility(View.GONE);
                            }
                        }


                    }
                    twoHolder.newly_ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type == 6) {
                                if (sharedPrefUtil.getString(context, ShareFile.USERFILE,
                                        ShareFile.ISNEWYOUKE, "0").equals("0")) {
                                    Toast.makeText(context, "请注册", Toast.LENGTH_SHORT).show();
                                } else {
                                    Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                    intent.putExtra("where", where);
                                    intent.putExtra("wheretype", 1);
                                    intent.putExtra("content", title.isEmpty() ? title1 : title);
                                    intent.putExtra("id", 0);
                                    intent.putExtra("uid", uid);
                                    intent.putExtra("titleid", titleId);
                                    intent.putExtra("style", stylee);
                                    intent.putExtra("title", title);
                                    intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                    startActivity(intent);
                                }
                            } else {
                                Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                intent.putExtra("where", where);
                                intent.putExtra("wheretype", 1);
                                intent.putExtra("content", title.isEmpty() ? title1 : title);
                                intent.putExtra("id", 0);
                                intent.putExtra("uid", uid);
                                intent.putExtra("style", stylee);
                                intent.putExtra("titleid", titleId);
                                intent.putExtra("title", title);
                                intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 2:
                    final ViewHolder finalHolder = holder;
                    holder.ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                if (finalHolder.ch.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate == 0 ? 1 : 0;
                                    clickEndstate(position - 1, endstate, list.get(position - 1).id, 0, finalHolder.ch, 1);
                                } else if (finalHolder.santai.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate;
                                    if (endstate == 0) {
                                        clickEndstate(position - 1, 1, list.get(position - 1).id, 1, finalHolder.santai, 1);
                                    } else if (endstate == 1) {
                                        clickEndstate(position - 1, 2, list.get(position - 1).id, 1, finalHolder.santai, 1);
                                    } else if (endstate == 2) {
                                        clickEndstate(position - 1, 0, list.get(position - 1).id, 1, finalHolder.santai, 1);
                                    }
                                }
                            }

                        }
                    });

                    holder.cl.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                intentLy(position - 1);
                            }
                        }
                    });

                    if (list.size() > 0) {

                        NoteLYBean.PageBean.ItemsBean itemsBean = App.getDBcApplication().getOneNoteLYData(titleId, list.get(position - 1).id);
                        if (itemsBean != null) {
                            if (itemsBean.mess != null && itemsBean.lyName != null && itemsBean.cId == list.get(position - 1).id) {
                                holder.ly_tv.setVisibility(View.VISIBLE);
                                holder.ly_tv.setText("@" + itemsBean.lyName + ": " + itemsBean.mess);
                            } else {
                                holder.ly_tv.setVisibility(View.GONE);
                            }
                            if (type != 5) {
                                if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, list.get(position - 1).id) == 1) {
                                    holder.guoqi_img.setVisibility(View.VISIBLE);
                                } else {
                                    holder.guoqi_img.setVisibility(View.GONE);
                                }
                            }
                        }

                        if (!istitle1) {
                            if (!list.get(position - 1).contents.isEmpty()) {
                                title1 = list.get(position - 1).contents;
                                sendh(0);
                                istitle1 = true;
                            }
                        }

                        if (stylee == 0) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_unfinish_c));
                                } else {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_finish_c));
                                }
                            }
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 1) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.VISIBLE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 2) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 3) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                            holder.emty_v.setVisibility(View.VISIBLE);
                        } else if (stylee == 4) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai1));
                                } else if (list.get(position - 1).endstate == 1) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai2));
                                } else {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai3));
                                }
                            }
                        }

                        setcolor(list.get(position - 1).contents, holder.content_tv);
                        holder.xh.setText((position) + ".");
                    }

                    break;
            }
            return convertView;
        }


        class ViewHolder {
            TextView xh, content_tv, ly_tv;
            ImageView ch, dd, santai, guoqi_img;
            View emty_v, line;
            RelativeLayout ll;
            LinearLayout cl;
        }

        class OneHolder {
            TextView title, username, number;
            ImageView header_image;
        }

        class TwoHolder {
            TextView checkAlltext, lttext, number, zan, zan_num;
            LinearLayout newly_ll;
            ImageView guoqi_img;
        }

    }

    class ListAdapter3 extends BaseAdapter {

        List<NoteTitleDetailBean.ListBean> list;

        public ListAdapter3(List<NoteTitleDetailBean.ListBean> list) {
            this.list = list;
        }

        public void updateEndstate(int position, int endstate) {
            list.get(position).endstate = endstate;
        }

        public String nums() {
            int tick1 = 0;
            int tick2 = 0;
            for (NoteTitleDetailBean.ListBean listBean : list) {
                if (listBean.endstate == 1) {
                    tick1 += 1;
                }
                if (listBean.endstate == 2) {
                    tick2 += 1;
                }
            }
            String title_new;
            if (stylee == 0) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + list.size();
                }
            } else if (stylee == 4) {
                if (list.size() == 0) {
                    title_new = "0";
                } else {
                    title_new = tick1 + "/" + tick2 + "/" + list.size();
                }
            } else {
                title_new = list.size() + "";
            }

            return title_new;
        }

        @Override
        public int getCount() {
            return list.size() + 2;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public int getItemViewType(int position) {
            if (position == 0) {
                return 0;
            } else if (position == list.size() + 1) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public int getViewTypeCount() {
            return 3;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            OneHolder oneHolder = null;
            TwoHolder twoHolder = null;
            int viewtype = getItemViewType(position);
            if (convertView == null) {
                switch (viewtype) {
                    case 0:
                        oneHolder = new OneHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_header_view, parent, false);
                        oneHolder.title = (TextView) convertView.findViewById(R.id.title);
                        oneHolder.username = (TextView) convertView.findViewById(R.id.username);
                        oneHolder.header_image = (ImageView) convertView.findViewById(R.id.header_image);
                        convertView.setTag(oneHolder);
                        break;
                    case 1:
                        twoHolder = new TwoHolder();
                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.dx_detail_foolter_view, parent, false);
                        twoHolder.checkAlltext = (TextView) convertView.findViewById(R.id.checkAlltext);
                        twoHolder.lttext = (TextView) convertView.findViewById(R.id.lttext);
                        twoHolder.number = (TextView) convertView.findViewById(R.id.number);
                        twoHolder.zan = (TextView) convertView.findViewById(R.id.zan);
                        twoHolder.zan_num = (TextView) convertView.findViewById(R.id.zan_num);
                        twoHolder.newly_ll = (LinearLayout) convertView.findViewById(R.id.newly_ll);
                        twoHolder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        convertView.setTag(twoHolder);
                        break;
                    case 2:
                        holder = new ViewHolder();

                        convertView = LayoutInflater.from(QDFXDetailActivity.this).inflate(R.layout.qdfx_de_list_item, parent, false);
                        holder.content_tv = (TextView) convertView.findViewById(R.id.content_tv);
                        holder.xh = (TextView) convertView.findViewById(R.id.xh);
                        holder.dd = (ImageView) convertView.findViewById(R.id.dd);
                        holder.ch = (ImageView) convertView.findViewById(R.id.ch);
                        holder.guoqi_img = (ImageView) convertView.findViewById(R.id.guoqi_img);
                        holder.ll = (RelativeLayout) convertView.findViewById(R.id.ll);
                        holder.santai = (ImageView) convertView.findViewById(R.id.santai);
                        holder.emty_v = convertView.findViewById(R.id.emty_v);
                        holder.line = convertView.findViewById(R.id.line);
                        holder.cl = (LinearLayout) convertView.findViewById(R.id.cl);
                        holder.ly_tv = (TextView) convertView.findViewById(R.id.ly_tv);

                        convertView.setTag(holder);
                        break;
                }
            } else {
                switch (viewtype) {
                    case 0:
                        oneHolder = (OneHolder) convertView.getTag();
                        break;
                    case 1:
                        twoHolder = (TwoHolder) convertView.getTag();
                        break;
                    case 2:
                        holder = (ViewHolder) convertView.getTag();
                        break;
                }
            }
            switch (viewtype) {
                case 0:
                    if (title.isEmpty()) {
                        oneHolder.title.setVisibility(View.GONE);
                    } else {
                        oneHolder.title.setText(title);
                    }

                    oneHolder.username.setText("@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));

                    if (path.isEmpty()) {
                        oneHolder.header_image.setVisibility(View.GONE);
                    } else {
                        oneHolder.header_image.setVisibility(View.VISIBLE);
                        String imageUrl = URLConstants.图片 + path + "&imageType=15&imageSizeType=1";
                        ImageLoader.getInstance().displayImage(imageUrl, oneHolder.header_image, base_options);
                    }

                    oneHolder.username.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                Intent intent = new Intent(context, NoteOtherListActivity.class);
                                intent.putExtra("name", name);
                                intent.putExtra("puid", uid);
                                startActivity(intent);
                            }
                        }
                    });
                    break;
                case 1:
                    if (type == 5) {
                        twoHolder.newly_ll.setVisibility(View.GONE);
                    } else {
                        twoHolder.newly_ll.setVisibility(View.VISIBLE);
                    }
                    twoHolder.number.setText("浏览" + StringUtils.getIsStringEqulesNull(rednum) + "次");
                    twoHolder.zan_num.setText(StringUtils.getIsStringEqulesNull(goodnum) + "人");
                    twoHolder.zan.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (!isGood) {
                                good();
                            }
                        }
                    });
                    if (type != 1 && type != 5) {
                        String rizhi = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CHANGJIANDIANZAN, "");
                        String[] ri = rizhi.split(",");
                        if (ri.length > 0) {
                            for (String item : ri) {
                                if (item.equals(titleId)) {
                                    twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                                    twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                                    isGood = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (isGood) {
                        twoHolder.zan.setTextColor(getResources().getColor(R.color.gongkai_txt));
                        twoHolder.zan.setBackground(getResources().getDrawable(R.drawable.zan_y_gray));
                    }
                    if (type != 5) {
                        where = "";
                        if (delListBeanList.size() > 0) {
                            for (DownSendNoteCalnderBean.DelListBean bean : delListBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (listBeanList.size() > 0) {
                            for (QDBean.ListBean bean : listBeanList) {
                                where += bean.id + ",";
                            }
                        } else if (locallistBeanList.size() > 0) {
                            for (NoteTitleDetailBean.ListBean bean : locallistBeanList) {
                                where += bean.id + ",";
                            }
                        }
                        if (where.isEmpty()) {
                            where = " cId = 0 ";
                        } else {
                            where = " cId not in (" + where.substring(0, where.length() - 1) + ") ";
                        }
                        NoteLYBean.PageBean.ItemsBean bean = App.getDBcApplication().getOneNoteLYData(titleId, where);
                        if (bean != null) {
                            twoHolder.lttext.setText("@" + bean.lyName + ": " + bean.mess);

                            if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, bean.id) == 1) {
                                twoHolder.guoqi_img.setVisibility(View.VISIBLE);
                            } else {
                                twoHolder.guoqi_img.setVisibility(View.GONE);
                            }
                        }

                    }
                    twoHolder.newly_ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type == 6) {
                                if (sharedPrefUtil.getString(context, ShareFile.USERFILE,
                                        ShareFile.ISNEWYOUKE, "0").equals("0")) {
                                    Toast.makeText(context, "请注册", Toast.LENGTH_SHORT).show();
                                } else {
                                    Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                    intent.putExtra("where", where);
                                    intent.putExtra("wheretype", 1);
                                    intent.putExtra("content", title.isEmpty() ? title1 : title);
                                    intent.putExtra("id", 0);
                                    intent.putExtra("uid", uid);
                                    intent.putExtra("titleid", titleId);
                                    intent.putExtra("style", stylee);
                                    intent.putExtra("title", title);
                                    intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                    startActivity(intent);
                                }
                            } else {
                                Intent intent = new Intent(QDFXDetailActivity.this, QDFXDetailLYActivity.class);
                                intent.putExtra("where", where);
                                intent.putExtra("wheretype", 1);
                                intent.putExtra("content", title.isEmpty() ? title1 : title);
                                intent.putExtra("id", 0);
                                intent.putExtra("uid", uid);
                                intent.putExtra("titleid", titleId);
                                intent.putExtra("style", stylee);
                                intent.putExtra("title", title);
                                intent.putExtra("nametime", "@" + name + " " + time.substring(5, time.length() - 3).replace('T', ' '));
                                startActivity(intent);
                            }

                        }
                    });
                    break;
                case 2:
                    final ViewHolder finalHolder = holder;
                    holder.ll.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                if (finalHolder.ch.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate == 0 ? 1 : 0;
                                    clickEndstate(position - 1, endstate, list.get(position - 1).id, 0, finalHolder.ch, 2);
                                } else if (finalHolder.santai.getVisibility() == View.VISIBLE) {
                                    int endstate = list.get(position - 1).endstate;
                                    if (endstate == 0) {
                                        clickEndstate(position - 1, 1, list.get(position - 1).id, 1, finalHolder.santai, 2);
                                    } else if (endstate == 1) {
                                        clickEndstate(position - 1, 2, list.get(position - 1).id, 1, finalHolder.santai, 2);
                                    } else if (endstate == 2) {
                                        clickEndstate(position - 1, 0, list.get(position - 1).id, 1, finalHolder.santai, 2);
                                    }
                                }
                            }

                        }
                    });

                    holder.cl.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (type != 5) {
                                intentLy(position - 1);
                            }
                        }
                    });

                    if (list.size() > 0) {

                        NoteLYBean.PageBean.ItemsBean itemsBean = App.getDBcApplication().getOneNoteLYData(titleId, list.get(position - 1).id);
                        if (itemsBean != null) {
                            if (itemsBean.mess != null && itemsBean.lyName != null && itemsBean.cId == list.get(position - 1).id) {
                                holder.ly_tv.setVisibility(View.VISIBLE);
                                holder.ly_tv.setText("@" + itemsBean.lyName + ": " + itemsBean.mess);
                            } else {
                                holder.ly_tv.setVisibility(View.GONE);
                            }
                            if (type != 5) {
                                if (App.getDBcApplication().getOneNoteLYDataIsRead(titleId, list.get(position - 1).id) == 1) {
                                    holder.guoqi_img.setVisibility(View.VISIBLE);
                                } else {
                                    holder.guoqi_img.setVisibility(View.GONE);
                                }
                            }
                        }

                        if (!istitle1) {
                            if (!list.get(position - 1).contents.isEmpty()) {
                                title1 = list.get(position - 1).contents;
                                sendh(0);
                                istitle1 = true;
                            }
                        }

                        if (stylee == 0) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_unfinish_c));
                                } else {
                                    holder.ch.setBackground(getResources().getDrawable(R.mipmap.btn_qd_finish_c));
                                }
                            }
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 1) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.VISIBLE);
                            holder.xh.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 2) {
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.GONE);
                        } else if (stylee == 3) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.GONE);
                            holder.santai.setVisibility(View.GONE);
                            holder.emty_v.setVisibility(View.VISIBLE);
                        } else if (stylee == 4) {
                            holder.ch.setVisibility(View.GONE);
                            holder.dd.setVisibility(View.GONE);
                            holder.xh.setVisibility(View.GONE);
                            holder.ll.setVisibility(View.VISIBLE);
                            holder.santai.setVisibility(View.VISIBLE);
                            if (type != 1) {
                                if (list.get(position - 1).endstate == 0) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai1));
                                } else if (list.get(position - 1).endstate == 1) {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai2));
                                } else {
                                    holder.santai.setBackground(getResources().getDrawable(R.mipmap.icon_santai3));
                                }
                            }
                        }

                        setcolor(list.get(position - 1).contents, holder.content_tv);
                        holder.xh.setText((position) + ".");
                    }

                    break;
            }
            return convertView;
        }


        class ViewHolder {
            TextView xh, content_tv, ly_tv;
            ImageView ch, dd, santai, guoqi_img;
            View emty_v, line;
            RelativeLayout ll;
            LinearLayout cl;
        }

        class OneHolder {
            TextView title, username, number;
            ImageView header_image;
        }

        class TwoHolder {
            TextView checkAlltext, lttext, number, zan, zan_num;
            LinearLayout newly_ll;
            ImageView guoqi_img;
        }

    }

    //设置双#号包裹的文字颜色
    private void setcolor(String content, TextView editText) {
        if (content.length() > 1) {
            SpannableStringBuilder builder = new SpannableStringBuilder(content);
            List<Integer> integerList = new ArrayList<>();
            int index = 0;
            int count = hit(content, "#");
            if (count > 1) {
                if (count % 2 == 0) {
                    for (int i = 0; i < count; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);
                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                } else {
                    for (int i = 0; i < count - 1; i++) {
                        if (i == 0) {
                            index = content.indexOf("#");
                        } else {
                            index = content.indexOf("#", index + 1);
                        }
                        integerList.add(index);

                    }
                    for (int i = 0; i < integerList.size(); i++) {
                        if (i > 0) {
                            if (i % 2 != 0) {
                                ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor("#df7926"));
                                builder.setSpan(span, integerList.get(i - 1), integerList.get(i) + 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                            }
                        }
                    }
                    editText.setText(builder);
                }
            } else {
                editText.setText(content);
            }
        } else {
            editText.setText(content);
        }
        editText.setLineSpacing(20, 1.5f);
    }

    /**
     * @param a 被匹配的长字符串
     * @param b 匹配的短字符串
     * @return 匹配次数
     */
    public int hit(String a, String b) {
        if (a.length() < b.length()) {
            return 0;
        }
        char[] a_t = a.toCharArray();
        int count = 0;

        for (int i = 0; i < a.length(); i++) {
            StringBuffer buffer = new StringBuffer();
            for (int j = 0; j < b.length(); j++) {
                buffer.append(a_t[i + j]);
            }
            if (buffer.toString().equals(b)) {
                count++;
            }
        }

        return count;
    }


    public class QDBean {

        /**
         * status : 0
         * downTime : 2017-06-02T10:14:53
         * message : 成功
         * list : [{"ltype":1,"orderId":0,"states":2,"style":3,"remark1":null,"uname":"清流暖人心","cpath":"","remark2":null,"goodNum":5,"shareUrl":null,"contents":"七个戒烟方法","remark3":null,"isTop":0,"id":4504,"redNum":111,"remark4":null,"uid":260975,"num":"20170523172148548492","endstate":null,"imgUrl":"","remark5":null,"titleId":"20170523172045176901","titles":"七个戒烟方法","changeTime":"2017-05-25T11:47:32","remark6":null,"remark":"1","createTime":"2017-05-23T17:21:48","curl":"","imgPath":""}]
         * tDelList : null
         * delList : null
         */

        public int status;
        public String downTime;
        public String message;
        public Object tDelList;
        public Object delList;
        public List<ListBean> list;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public Object getDelList() {
            return delList;
        }

        public void setDelList(Object delList) {
            this.delList = delList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean implements Serializable {
            /**
             * ltype : 1
             * orderId : 0
             * states : 2
             * style : 3
             * remark1 : null
             * uname : 清流暖人心
             * cpath :
             * remark2 : null
             * goodNum : 5
             * shareUrl : null
             * contents : 七个戒烟方法
             * remark3 : null
             * isTop : 0
             * id : 4504
             * redNum : 111
             * remark4 : null
             * uid : 260975
             * num : 20170523172148548492
             * endstate : null
             * imgUrl :
             * remark5 : null
             * titleId : 20170523172045176901
             * titles : 七个戒烟方法
             * changeTime : 2017-05-25T11:47:32
             * remark6 : null
             * remark : 1
             * createTime : 2017-05-23T17:21:48
             * curl :
             * imgPath :
             */

            public int ltype;
            public int orderId;
            public int states;
            public int style;
            public String remark1;
            public String uname;
            public String cpath;
            public String remark2;
            public int goodNum;
            public String shareUrl;
            public String contents;
            public String remark3;
            public int isTop;
            public int id;
            public int redNum;
            public String remark4;
            public int uid;
            public String num;
            public int endstate;
            public String imgUrl;
            public String remark5;
            public String titleId;
            public String titles;
            public String changeTime;
            public String remark6;
            public String remark;
            public String createTime;
            public String curl;
            public String imgPath;

            public int getLtype() {
                return ltype;
            }

            public void setLtype(int ltype) {
                this.ltype = ltype;
            }

            public int getOrderId() {
                return orderId;
            }

            public void setOrderId(int orderId) {
                this.orderId = orderId;
            }

            public int getStates() {
                return states;
            }

            public void setStates(int states) {
                this.states = states;
            }

            public int getStyle() {
                return style;
            }

            public void setStyle(int style) {
                this.style = style;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public String getUname() {
                return uname;
            }

            public void setUname(String uname) {
                this.uname = uname;
            }

            public String getCpath() {
                return cpath;
            }

            public void setCpath(String cpath) {
                this.cpath = cpath;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public int getGoodNum() {
                return goodNum;
            }

            public void setGoodNum(int goodNum) {
                this.goodNum = goodNum;
            }

            public String getShareUrl() {
                return shareUrl;
            }

            public void setShareUrl(String shareUrl) {
                this.shareUrl = shareUrl;
            }

            public String getContents() {
                return contents;
            }

            public void setContents(String contents) {
                this.contents = contents;
            }

            public String getRemark3() {
                return remark3;
            }

            public void setRemark3(String remark3) {
                this.remark3 = remark3;
            }

            public int getIsTop() {
                return isTop;
            }

            public void setIsTop(int isTop) {
                this.isTop = isTop;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public int getRedNum() {
                return redNum;
            }

            public void setRedNum(int redNum) {
                this.redNum = redNum;
            }

            public String getRemark4() {
                return remark4;
            }

            public void setRemark4(String remark4) {
                this.remark4 = remark4;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }

            public String getNum() {
                return num;
            }

            public void setNum(String num) {
                this.num = num;
            }

            public int getEndstate() {
                return endstate;
            }

            public void setEndstate(int endstate) {
                this.endstate = endstate;
            }

            public String getImgUrl() {
                return imgUrl;
            }

            public void setImgUrl(String imgUrl) {
                this.imgUrl = imgUrl;
            }

            public String getRemark5() {
                return remark5;
            }

            public void setRemark5(String remark5) {
                this.remark5 = remark5;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public String getTitles() {
                return titles;
            }

            public void setTitles(String titles) {
                this.titles = titles;
            }

            public String getChangeTime() {
                return changeTime;
            }

            public void setChangeTime(String changeTime) {
                this.changeTime = changeTime;
            }

            public String getRemark6() {
                return remark6;
            }

            public void setRemark6(String remark6) {
                this.remark6 = remark6;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }

            public String getCreateTime() {
                return createTime;
            }

            public void setCreateTime(String createTime) {
                this.createTime = createTime;
            }

            public String getCurl() {
                return curl;
            }

            public void setCurl(String curl) {
                this.curl = curl;
            }

            public String getImgPath() {
                return imgPath;
            }

            public void setImgPath(String imgPath) {
                this.imgPath = imgPath;
            }
        }
    }

    int[] solartime = new int[25];
    boolean isLeap = false;
    boolean isRed = false;
    ArrayList<HashMap<String, String>> data;
    String today;
    int temp_day;
    int temp_month;
    int temp_year;

    int to_day;
    int to_month;
    int to_year;
    int standard_day;
    int standard_month;
    int standard_year;
    String holiday = "";
    String curDate = "";

    int sourse;//
    String dateTime = "";// 日期
    private TextView titleTV;

    MyLinearLayout dataLinear;
    Handler handlerrili;
    LinearLayout.LayoutParams mLayoutParamss = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);

    private void initRiliDiaLog(final String content) {
        final Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_rili, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();

        curDate = dateTime;

        dataLinear = (MyLinearLayout) more_pop_menu.findViewById(R.id.datalinear);
        titleTV = (TextView) more_pop_menu.findViewById(R.id.title);
        dataLinear.setBackgroundColor(Color.WHITE);
        more_pop_menu.findViewById(R.id.today).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                curDate = DateUtil.formatDate(new Date());// new Date()为获取当前系统时间
                GenData(true, curDate);
                GenView();
            }
        });
        more_pop_menu.findViewById(R.id.lastmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 1) {
                    standard_month = 12;
                    standard_year--;
                } else {
                    standard_month--;
                }
                GenData(false, curDate);
                GenView();
                titleTV.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));

            }
        });
        more_pop_menu.findViewById(R.id.nextmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 12) {
                    standard_month = 1;
                    standard_year++;
                } else {
                    standard_month++;
                }
                GenData(false, curDate);
                GenView();
                titleTV.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));

            }
        });
        handlerrili = new Handler() {
            public void handleMessage(Message msg) {
                if (msg == null) {
                    return;
                }
                switch (msg.what) {
                    case 0:
                        if (standard_month == 1) {
                            standard_month = 12;
                            standard_year--;
                        } else {
                            standard_month--;
                        }
                        GenData(false, curDate);
                        GenView();
                        titleTV.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.right_in));
                        break;

                    case 1:
                        if (standard_month == 12) {
                            standard_month = 1;
                            standard_year++;
                        } else {
                            standard_month++;
                        }
                        GenData(false, curDate);
                        GenView();
                        titleTV.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.left_in));
                        break;

                    case 2:
                        standard_year--;
                        GenData(false, curDate);
                        GenView();
                        titleTV.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.down_in));
                        break;

                    case 3:
                        standard_year++;
                        GenData(false, curDate);
                        GenView();
                        titleTV.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(context, R.anim.up_in));
                        break;

                    case 9:
                        dialog.dismiss();

                        App.getDBcApplication().insertScheduleData(content, msg.obj + "",
                                DateUtil.nowTimes(), 1,
                                0, 1, 0, 0,
                                0, 0, DateUtil.formatDateTime(new Date()), "", type == 5 ? 1 : 0,
                                type == 5 ? num : titleId, DateUtil.formatDateTimeSs(new Date()), 0, "", DateUtil.formatDateTime(new Date()),
                                1, 0, 0, "完成任务", "g_88", type == 5 ? "发现" : name, 0, 0, 0, "",
                                "", 0, 0, Integer.valueOf(uid),0,"","0","0");

                        addNums(titleId);
                        Intent intent = new Intent(Const.SHUAXINDATA);
                        intent.putExtra("data", "success");
                        intent.putExtra("index", 1);
                        intent.putExtra("what", 2);
                        context.sendBroadcast(intent);
                        QueryAlarmData.writeAlarm(context);

                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        context.sendBroadcast(intentappwidget);

                        Toast.makeText(context, "添加成功", Toast.LENGTH_LONG).show();
                        break;

                    case 11:
                        Toast.makeText(context, "网络中断", Toast.LENGTH_LONG).show();
                        break;

                    case 12:
                        Toast.makeText(context, "服务器错误", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        };
        dataLinear.setHandler(handlerrili);


        new LoadDataAsyncTask().execute();


    }

    class LoadDataAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
//			dialog.dismiss();
            GenData(true, curDate);
            GenView();
        }

    }

    public ArrayList<HashMap<String, String>> GenData(boolean isfirst, String date) {
        if (!date.equals("") && isfirst) {
            data = new ArrayList<HashMap<String, String>>();
            to_year = Integer.parseInt(date.split("-")[0].toString());
            to_month = Integer.parseInt(date.split("-")[1].toString());
            to_day = Integer.parseInt(date.split("-")[2].toString());
            temp_day = to_day;
            temp_month = to_month;
            temp_year = to_year;
            standard_day = to_day;
            standard_month = to_month;
            standard_year = to_year;
            today = date;
            titleTV.setText(standard_year + "年" + standard_month + "月");
        } else {
            if (isfirst) {
                data = new ArrayList<HashMap<String, String>>();
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis());
                to_year = c.get(Calendar.YEAR);
                to_month = c.get(Calendar.MONTH);
                to_day = c.get(Calendar.DAY_OF_MONTH);

                to_month++;
                temp_day = to_day;
                temp_month = to_month;
                temp_year = to_year;
                standard_day = to_day;
                standard_month = to_month;
                standard_year = to_year;

                today = to_year + "-"
                        + (to_month > 9 ? "" + to_month : "0" + to_month) + "-"
                        + (to_day > 9 ? "" + to_day : "0" + to_day);
                titleTV.setText(standard_year + "年" + standard_month + "月");
            } else {
                data = new ArrayList<HashMap<String, String>>();
                temp_day = standard_day;
                temp_month = standard_month;
                temp_year = standard_year;

            }
        }
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("day", temp_day + "");

        map.put("isMonth", "1"); // 1是本月
        String tempStrT = temp_year + "-"
                + (temp_month > 9 ? "" + temp_month : "0" + temp_month) + "-"
                + (temp_day > 9 ? "" + temp_day : "0" + temp_day);
        if ("".equals(StringUtils.getIsStringEqulesNull(tempStrT))) {
            tempStrT = today;
        }
        if (today.equals(tempStrT)) {
            map.put("isToday", "1"); // 1是今天
            map.put("time", today);
        } else {
            map.put("isToday", "0"); // 1是今天
            map.put("time", tempStrT);
        }
        try {
            if (CalHoliday(Integer.valueOf(temp_month
                    + (temp_day > 9 ? "" + temp_day : "0" + temp_day)))) {
                map.put("lunar", holiday);
            } else {
                map.put("lunar", CalendarChange.CalendarChange(tempStrT));
            }
            if (isRed) {
                map.put("isHoliday", "1"); // 1节日
                isRed = false;
            } else {
                map.put("isHoliday", "0"); // 1节日
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.add(map);
        for (int i = temp_day - 1; i > 0; i--) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 1是今天
            map.put("isMonth", "1"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(0, map);
        }
        int te_week = calWeek(temp_year, temp_month, 1);
        if (temp_month == 1) {
            temp_year--;
            temp_month = 12;
        } else {
            temp_month--;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = 30; i > 30 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = 29; i > 29 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            } else {
                for (int i = 28; i > 28 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            }
        } else {
            for (int i = 31; i > 31 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        }
        if (temp_month == 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month = temp_month + 1;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = to_day + 1; i <= 30; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = to_day + 1; i <= 29; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            } else {
                for (int i = to_day + 1; i <= 28; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + to_day);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            }
        } else {
            for (int i = to_day + 1; i <= 31; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        }
        if (temp_month >= 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month++;
        }
        int mm = data.size();
        for (int i = 1; i <= 42 - mm; i++) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 是今天
            map.put("isMonth", "0"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(map);
        }
        return data;
    }

    public boolean CalHoliday(int t) {
        boolean is = false;
        switch (t / 100) {
            case 2:
                if (t == solartime[0]) {
                    holiday = "立春";
                    is = true;
                } else if (t == solartime[1]) {
                    holiday = "雨水";
                    is = true;
                }
                break;
            case 3:
                if (t == solartime[2]) {
                    holiday = "惊蛰";
                    is = true;
                } else if (t == solartime[3]) {
                    holiday = "春分";
                    is = true;
                }
                break;
            case 4:
                if (t == solartime[4]) {
                    holiday = "清明";
                    is = true;
                } else if (t == solartime[5]) {
                    holiday = "谷雨";
                    is = true;
                }
                break;
            case 5:
                if (t == solartime[6]) {
                    holiday = "立夏";
                    is = true;
                } else if (t == solartime[7]) {
                    holiday = "小满";
                    is = true;
                }
                break;
            case 6:
                if (t == solartime[8]) {
                    holiday = "芒种";
                    is = true;
                } else if (t == solartime[9]) {
                    holiday = "夏至";
                    is = true;
                }
                break;
            case 7:
                if (t == solartime[10]) {
                    holiday = "小暑";
                    is = true;
                } else if (t == solartime[11]) {
                    holiday = "大暑";
                    is = true;
                }
                break;
            case 8:
                if (t == solartime[12]) {
                    holiday = "立秋";
                    is = true;
                } else if (t == solartime[13]) {
                    holiday = "处暑";
                    is = true;
                }
                break;
            case 9:
                if (t == solartime[14]) {
                    holiday = "白露";
                    is = true;
                } else if (t == solartime[15]) {
                    holiday = "秋分";
                    is = true;
                }
                break;
            case 10:
                if (t == solartime[16]) {
                    holiday = "寒露";
                    is = true;
                } else if (t == solartime[17]) {
                    holiday = "霜降";
                    is = true;
                }
                break;
            case 11:
                if (t == solartime[18]) {
                    holiday = "立冬";
                    is = true;
                } else if (t == solartime[19]) {
                    holiday = "小雪";
                    is = true;
                }
                break;
            case 12:
                if (t == solartime[20]) {
                    holiday = "大雪";
                    is = true;
                } else if (t == solartime[21]) {
                    holiday = "冬至";
                    is = true;
                }
                break;
            case 1:
                if (t == solartime[22]) {
                    holiday = "小寒";
                    is = true;
                } else if (t == solartime[23]) {
                    holiday = "大寒";
                    is = true;
                }
                break;
        }
        switch (t) {
            case 101:
                holiday = "元旦";
                isRed = true;
                is = true;
                break;
            case 214:
                holiday = "情人节";
                is = true;
                break;
            case 308:
                holiday = "妇女节";
                is = true;
                break;
            case 312:
                holiday = "植树节";
                is = true;
                break;
            case 315:
                holiday = "消费日";
                is = true;
                break;
            case 401:
                holiday = "愚人节";
                is = true;
                break;
            // case 407:
            // holiday="卫生日";
            // is=true;
            // break;
            case 501:
                holiday = "劳动节";
                is = true;
                break;
            case 504:
                holiday = "青年节";
                is = true;
                break;
            // case 512:
            // holiday="护士节";
            // is=true;
            // break;
            // case 513:
            // holiday="助残日";
            // is=true;
            // break;

            case 601:
                holiday = "儿童节";
                is = true;
                break;
            case 605:
                holiday = "世界环境日";
                is = true;
                break;
            case 701:
                holiday = "建党节";
                is = true;
                break;
            case 801:
                holiday = "建军节";
                is = true;
                break;
            case 910:
                holiday = "教师节";
                is = true;
                break;
            case 1001:
                holiday = "国庆节";
                is = true;
                break;
            case 1225:
                holiday = "圣诞节";
                is = true;
                break;
            default:
                // is=false;
                break;
        }

        return is;
    }

    @SuppressWarnings("deprecation")
    public void GenView() {
        dataLinear.removeAllViews();
        mLayoutParamss.weight = 1;
        LayoutInflater lif = LayoutInflater.from(context);
        LinearLayout temp = new LinearLayout(context);
        int size = data.size();
        for (int i = 0; i < size; i++) {
            View convertView = lif.inflate(R.layout.gritem, null);
            TextView time = (TextView) convertView.findViewById(R.id.time);
            TextView lunar = (TextView) convertView.findViewById(R.id.lunar);
            TextView fraction = (TextView) convertView.findViewById(R.id.fraction);
            LinearLayout itemroot = (LinearLayout) convertView.findViewById(R.id.itemroot);
            HashMap<String, String> map = data.get(i);
            if ((i + 1) < size) {
                HashMap<String, String> map2 = data.get(i + 1);
                if (map2.get("lunar").equals("春节")) {
                    map.put("lunar", "除夕");
                }
            }
            if (map.get("isMonth").equals("1"))// 1是本月
            {
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                if (map.get("isToday").equals("1"))// 1是今天
                {
                    time.setTextColor(getResources().getColor(R.color.sunday_txt));
                    lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
//                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                } else {
                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                }
//                int m = (i + 1) % 7;
//                if (m == 1 || m == 0) {
//                    time.setTextColor(Color.rgb(50, 79, 133));
//                }
                if (map.get("isHoliday").equals("1")) // 节日
                {
                    time.setTextColor(Color.RED);
                }
                itemroot.setTag(R.id.calendar_index, "1");//0其他,1是本月
            } else {
                time.setTextColor(getResources().getColor(R.color.othermonth_txt));
                lunar.setTextColor(getResources().getColor(R.color.othermonth_txt));
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                itemroot.setTag(R.id.calendar_index, "0");
            }
            String day = map.get("day");
            String datestr = standard_year + "-" +
                    (standard_month > 9 ? standard_month : "0" + standard_month) + "-" +
                    (day.length() > 1 ? day : "0" + day);
            if (map.get("isMonth").equals("1")) {// 1是本月
                if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("1")) {//休息
                fraction.setText("休");
                fraction.setTextColor(getResources().getColor(R.color.sunday_txt));
            } else if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("2")) {//上班
                fraction.setText("班");
                fraction.setTextColor(getResources().getColor(R.color.title0));
            } else {
                fraction.setVisibility(View.GONE);
            }}
            if (!map.get("isMonth").equals("1")) {
                time.setVisibility(View.GONE);
                fraction.setVisibility(View.GONE);
                lunar.setVisibility(View.GONE);
            }
            time.setText(day);
            lunar.setText(map.get("lunar"));
            itemroot.setTag(day);
            itemroot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String day = v.getTag().toString();
                    // 0其他,1是本月
                    String calendar_index = v.getTag(R.id.calendar_index).toString();
                    if ("1".equals(calendar_index)) {
                        Intent intent = null;
                        String dateTime = Integer.toString(standard_year)
                                + "-"
                                + (standard_month > 9 ? "" + standard_month
                                : "0" + standard_month) + "-"
                                + (Integer.parseInt(day) > 9 ? day : "0" + day);
                        Message message = new Message();
                        message.what = 9;
                        message.obj = dateTime;
                        handlerrili.sendMessage(message);
                    }
                }
            });
            if ((i + 1) % 7 != 0) {
                temp.addView(convertView, mLayoutParamss);
            } else {
                if (i != 0) {
                    temp.addView(convertView, mLayoutParamss);
                    dataLinear.addView(temp, mLayoutParamss);
                    temp = new LinearLayout(context);
                }
            }
        }
    }

    /*
     * 基姆拉尔森计算公式 QgW4jIbx W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 /
     *
     * d 天 m 月 y 年 1月2月换算为去年的13 14月计算
     *
     * 基姆拉尔森计算公式的C#的实现 %NfbgJcL_ //y：年，m：月，d：日。在参数都只传入相应的整数
     */
    private int calWeek(int y, int m, int d) {
        int a = 7; // 用来保存计算得到的星期几的整数 Dz>v;%$S-
        if ((m == 1) || (m == 2))// 如果是一月或二月进行换算 uWKc .
        {
            m += 12;
            y--;
        }
        a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; // 得到的星期几的整数
        // 
        // 7ehs+GI
        a++;
        if (a == 7) {
            a = 0;
        }
        return a;
    }

    public void calLeapYear(int i) {
        if (i % 100 == 0) {
            if (i % 400 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        } else {
            if (i % 4 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        }
    }

    public class DownSendNoteCalnderBean {

        /**
         * status : 0
         * downTime : 2017-07-05T10:19:32
         * message : 成功
         * list : [{"orderId":0,"puid":0,"states":0,"filed":"1","openState":1,"pname":"","remark1":"0","remark2":"0","styles":0,"shareUrl":"","localTimes":"2017-06-07 13:43:17","remark3":"0","id":41490,"remark4":"0","uid":52432,"nums":"","imgUrl":"","titles":"记账猫测试问题14:42","titleId":"20170607134317985293","sends":0,"changeTime":"2017-06-09T13:25:44","createTime":"2017-06-09T13:25:44","remark":"0","copys":"1","imgPath":"","ltype":1}]
         * tDelList : null
         * delList : [{"style":null,"remark1":null,"cpath":"","remark2":null,"shareUrl":null,"contents":"#账户列表#","remark3":null,"id":46594,"lType":null,"remark4":null,"uid":52432,"nums":"0","endstate":0,"imgUrl":null,"titleId":"20170607134317985293","titles":null,"changetime":"2017-06-09T11:13:05","createTime":"2017-06-09T11:13:05","curl":"","imgPath":null,"orderId":0,"remark":null}]
         */

        public int status;
        public String downTime;
        public String message;
        public Object tDelList;
        public List<ListBean> list;
        public List<DelListBean> delList;

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getTDelList() {
            return tDelList;
        }

        public void setTDelList(Object tDelList) {
            this.tDelList = tDelList;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public List<DelListBean> getDelList() {
            return delList;
        }

        public void setDelList(List<DelListBean> delList) {
            this.delList = delList;
        }

        public class ListBean {
            /**
             * orderId : 0
             * puid : 0
             * states : 0
             * filed : 1
             * openState : 1
             * pname :
             * remark1 : 0
             * remark2 : 0
             * styles : 0
             * shareUrl :
             * localTimes : 2017-06-07 13:43:17
             * remark3 : 0
             * id : 41490
             * remark4 : 0
             * uid : 52432
             * nums :
             * imgUrl :
             * titles : 记账猫测试问题14:42
             * titleId : 20170607134317985293
             * sends : 0
             * changeTime : 2017-06-09T13:25:44
             * createTime : 2017-06-09T13:25:44
             * remark : 0
             * copys : 1
             * imgPath :
             * ltype : 1
             */

            public int orderId;
            public int puid;
            public int states;
            public String filed;
            public int openState;
            public String pname;
            public String remark1;
            public String remark2;
            public int styles;
            public String shareUrl;
            public String localTimes;
            public String remark3;
            public int id;
            public String remark4;
            public int uid;
            public String nums;
            public String imgUrl;
            public String titles;
            public String titleId;
            public int sends;
            public String changeTime;
            public String createTime;
            public String remark;
            public String copys;
            public String imgPath;
            public int ltype;

            public int getOrderId() {
                return orderId;
            }

            public void setOrderId(int orderId) {
                this.orderId = orderId;
            }

            public int getPuid() {
                return puid;
            }

            public void setPuid(int puid) {
                this.puid = puid;
            }

            public int getStates() {
                return states;
            }

            public void setStates(int states) {
                this.states = states;
            }

            public String getFiled() {
                return filed;
            }

            public void setFiled(String filed) {
                this.filed = filed;
            }

            public int getOpenState() {
                return openState;
            }

            public void setOpenState(int openState) {
                this.openState = openState;
            }

            public String getPname() {
                return pname;
            }

            public void setPname(String pname) {
                this.pname = pname;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public int getStyles() {
                return styles;
            }

            public void setStyles(int styles) {
                this.styles = styles;
            }

            public String getShareUrl() {
                return shareUrl;
            }

            public void setShareUrl(String shareUrl) {
                this.shareUrl = shareUrl;
            }

            public String getLocalTimes() {
                return localTimes;
            }

            public void setLocalTimes(String localTimes) {
                this.localTimes = localTimes;
            }

            public String getRemark3() {
                return remark3;
            }

            public void setRemark3(String remark3) {
                this.remark3 = remark3;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getRemark4() {
                return remark4;
            }

            public void setRemark4(String remark4) {
                this.remark4 = remark4;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }

            public String getNums() {
                return nums;
            }

            public void setNums(String nums) {
                this.nums = nums;
            }

            public String getImgUrl() {
                return imgUrl;
            }

            public void setImgUrl(String imgUrl) {
                this.imgUrl = imgUrl;
            }

            public String getTitles() {
                return titles;
            }

            public void setTitles(String titles) {
                this.titles = titles;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public int getSends() {
                return sends;
            }

            public void setSends(int sends) {
                this.sends = sends;
            }

            public String getChangeTime() {
                return changeTime;
            }

            public void setChangeTime(String changeTime) {
                this.changeTime = changeTime;
            }

            public String getCreateTime() {
                return createTime;
            }

            public void setCreateTime(String createTime) {
                this.createTime = createTime;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }

            public String getCopys() {
                return copys;
            }

            public void setCopys(String copys) {
                this.copys = copys;
            }

            public String getImgPath() {
                return imgPath;
            }

            public void setImgPath(String imgPath) {
                this.imgPath = imgPath;
            }

            public int getLtype() {
                return ltype;
            }

            public void setLtype(int ltype) {
                this.ltype = ltype;
            }
        }

        public class DelListBean implements Serializable {
            /**
             * style : null
             * remark1 : null
             * cpath :
             * remark2 : null
             * shareUrl : null
             * contents : #账户列表#
             * remark3 : null
             * id : 46594
             * lType : null
             * remark4 : null
             * uid : 52432
             * nums : 0
             * endstate : 0
             * imgUrl : null
             * titleId : 20170607134317985293
             * titles : null
             * changetime : 2017-06-09T11:13:05
             * createTime : 2017-06-09T11:13:05
             * curl :
             * imgPath : null
             * orderId : 0
             * remark : null
             */

            public String style;
            public String remark1;
            public String cpath;
            public String remark2;
            public String shareUrl;
            public String contents;
            public String remark3;
            public int id;
            public String lType;
            public String remark4;
            public int uid;
            public String nums;
            public int endstate;
            public String imgUrl;
            public String titleId;
            public String titles;
            public String changetime;
            public String createTime;
            public String curl;
            public String imgPath;
            public int orderId;
            public String remark;

            public String getStyle() {
                return style;
            }

            public void setStyle(String style) {
                this.style = style;
            }

            public String getRemark1() {
                return remark1;
            }

            public void setRemark1(String remark1) {
                this.remark1 = remark1;
            }

            public String getCpath() {
                return cpath;
            }

            public void setCpath(String cpath) {
                this.cpath = cpath;
            }

            public String getRemark2() {
                return remark2;
            }

            public void setRemark2(String remark2) {
                this.remark2 = remark2;
            }

            public String getShareUrl() {
                return shareUrl;
            }

            public void setShareUrl(String shareUrl) {
                this.shareUrl = shareUrl;
            }

            public String getContents() {
                return contents;
            }

            public void setContents(String contents) {
                this.contents = contents;
            }

            public String getRemark3() {
                return remark3;
            }

            public void setRemark3(String remark3) {
                this.remark3 = remark3;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getLType() {
                return lType;
            }

            public void setLType(String lType) {
                this.lType = lType;
            }

            public String getRemark4() {
                return remark4;
            }

            public void setRemark4(String remark4) {
                this.remark4 = remark4;
            }

            public int getUid() {
                return uid;
            }

            public void setUid(int uid) {
                this.uid = uid;
            }

            public String getNums() {
                return nums;
            }

            public void setNums(String nums) {
                this.nums = nums;
            }

            public int getEndstate() {
                return endstate;
            }

            public void setEndstate(int endstate) {
                this.endstate = endstate;
            }

            public String getImgUrl() {
                return imgUrl;
            }

            public void setImgUrl(String imgUrl) {
                this.imgUrl = imgUrl;
            }

            public String getTitleId() {
                return titleId;
            }

            public void setTitleId(String titleId) {
                this.titleId = titleId;
            }

            public String getTitles() {
                return titles;
            }

            public void setTitles(String titles) {
                this.titles = titles;
            }

            public String getChangetime() {
                return changetime;
            }

            public void setChangetime(String changetime) {
                this.changetime = changetime;
            }

            public String getCreateTime() {
                return createTime;
            }

            public void setCreateTime(String createTime) {
                this.createTime = createTime;
            }

            public String getCurl() {
                return curl;
            }

            public void setCurl(String curl) {
                this.curl = curl;
            }

            public String getImgPath() {
                return imgPath;
            }

            public void setImgPath(String imgPath) {
                this.imgPath = imgPath;
            }

            public int getOrderId() {
                return orderId;
            }

            public void setOrderId(int orderId) {
                this.orderId = orderId;
            }

            public String getRemark() {
                return remark;
            }

            public void setRemark(String remark) {
                this.remark = remark;
            }
        }
    }


    /**
     * 点击留言
     */
    private void alterImportantDialog(Context context, String message) {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent_adjustPan);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.add_reply_dialogs, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.show();

        new alterImportantDialogOnClick(context, dialog, more_pop_menu, message);
    }

    class alterImportantDialogOnClick implements View.OnClickListener {

        private View view;
        private Dialog dialog;
        private TextView add_tv;
        private TextView copy_tv;
        private TextView canel_tv;
        private String message;
        private Context context;

        @SuppressLint("NewApi")
        public alterImportantDialogOnClick(Context context, Dialog dialog, View view, String message) {
            this.dialog = dialog;
            this.view = view;
            this.message = message;
            this.context = context;
            initview();
        }

        private void initview() {
            copy_tv = (TextView) view.findViewById(R.id.copy_tv);
            copy_tv.setText("复制留言内容");
            copy_tv.setOnClickListener(this);
            canel_tv = (TextView) view.findViewById(R.id.canel_tv);
            canel_tv.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.copy_tv:
                    // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
                    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                    // 将文本内容放到系统剪贴板里。
                    cm.setText(message);
                    Toast.makeText(context, "已复制", Toast.LENGTH_SHORT).show();
                    dialog.dismiss();
                    break;
                case R.id.canel_tv:
                    dialog.dismiss();
                    break;
            }
        }
    }


    private void ly(String mess, int id) {
        String data = lyJsonStrinf(mess, 1, id);
        HttpUtils httpUtils = new HttpUtils(2000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("row1", "▶︎ @" + sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.USERNAME, "") + " " + mess);
        params.addBodyParameter("row2", "#" + (title.isEmpty() ? title1 : title) + "#");
        params.addBodyParameter("data", data);
        httpUtils.send(HttpMethod.POST, URLConstants.清单留言同步主留言信息, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                try {
                    if (listAdapter != null) {
                        listAdapter.notifyDataSetChanged();
                    }
                    if (listAdapter2 != null) {
                        listAdapter2.notifyDataSetChanged();
                    }
                    if (listAdapter3 != null) {
                        listAdapter3.notifyDataSetChanged();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
            }
        });
    }

    private void ly() {
        String data = lyJsonStrinf("查看了清单详情!", 1, 0);
        HttpUtils httpUtils = new HttpUtils(2000);
        RequestParams params = new RequestParams();
        params.addBodyParameter("row1", "▶︎ @" + sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "") + " 查看了清单详情");
        params.addBodyParameter("row2", "#" + (title.isEmpty() ? title1 : title) + "#");
        params.addBodyParameter("data", data);
        httpUtils.send(HttpMethod.POST, URLConstants.清单留言同步主留言信息, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                isRead = 0;
                try {
                    if (listAdapter != null) {
                        listAdapter.notifyDataSetChanged();
                    }
                    if (listAdapter2 != null) {
                        listAdapter2.notifyDataSetChanged();
                    }
                    if (listAdapter3 != null) {
                        listAdapter3.notifyDataSetChanged();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                isRead = 0;
            }
        });
    }

    private String lyJsonStrinf(String mess, int type, int id) {
        JSONObject ly = new JSONObject();
        try {
            JSONArray jsonArray = new JSONArray();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", -1);
            jsonObject.put("mess", mess);
            jsonObject.put("updateState", 1);
            jsonObject.put("uid", uid);
            jsonObject.put("lyUid", userid);
            jsonObject.put("lyName", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, ""));
            jsonObject.put("titleId", titleId);
            jsonObject.put("cId", id);
            jsonObject.put("localTimes", DateUtil.formatDateTimeSs(new Date()));
            jsonObject.put("type", type);//0 普通留言 1 系统留言
            jsonObject.put("reamrk1", android.os.Build.MODEL.replace(" ", "") + " " + android.os.Build.VERSION.RELEASE);
            jsonObject.put("lyTitleImg", sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERPHOTOPATH, ""));
            jsonObject.put("reamrk", title);
            jsonObject.put("changeTime", DateUtil.formatDateTimeSs(new Date()));
            jsonArray.put(jsonObject);
            ly.put("ly", jsonArray);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ly.toString();
    }
}
